package com.dsh.controller;

import com.aliyun.oss.OSS;
import com.dsh.common.response.Result;
import com.dsh.common.response.ResultObject;

import com.dsh.config.FastDFSClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("goods")
public class UploadController {
    @Autowired
    FastDFSClient fastDFSClient;
    @Autowired
    OSS ossClient;

    @Value("${oss.bucket}")
    String bucket;
    @Value("${oss.hostName}")
    String hostName;

    @RequestMapping("upload/image")
    public ResultObject<Map> uploadImage(@RequestParam("file")MultipartFile file) throws IOException {
        String fastDFS_url = fastDFSClient.upload(file);

        String originalFilename = file.getOriginalFilename();
        ossClient.putObject(bucket,originalFilename,file.getInputStream());
        String OSS_url=hostName+originalFilename;

        Map map=new HashMap();
        map.put("image",fastDFS_url);
        map.put("imageBak",OSS_url);

        return new ResultObject<>(true,"1","上传成功",map);

    }

   
}
